package com.xiaoluo.web;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xiaoluo.cd.entity.base.Servers;
import com.xiaoluo.service.ServerService;
import com.xiaoluo.web.form.ResultForm;
import com.xiaoluo.web.form.TreeNode;
import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Project : SpiderManager
 * Package : com.xiaoluo.web
 * Created by Willian.
 * Date  : 2015/10/21 20:29.
 */
@Controller
@RequestMapping("/server")
public class ServerController extends BaseController{
    private final static Logger logger = LoggerFactory.getLogger(ServerController.class);

    @Autowired
    private ServerService serverService;

    private KubernetesClient kubernetesClient;

    @RequestMapping(value = "/")
    public  String index(ModelMap model,String type){

        PodList pods = kubernetesClient.pods().list();
        model.addAttribute("pods",pods);
        model.addAttribute("type",type);
        return "server/index";
    }


    @RequestMapping(value = "/del",method = RequestMethod.GET)
    public  String del(ModelMap model,Long id){

        serverService.del(id);
        return "forward:list";
    }

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public  String save(ModelMap model,Servers servers){

        serverService.save(servers);
        return "forward:list";
    }

}
